package com.tencent.service.impl;

import com.tencent.config.ThreadPoolUtils;
import com.tencent.entity.SetMeal;
import com.tencent.mapper.ShowMapper;
import com.tencent.service.ShowpeoService1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

@Service
public class ShowpeoService2 implements ShowpeoService1 {

    @Autowired
    private ShowMapper showMapper;


    @Override
    public Map<String, Object> getBusinessReport() throws InterruptedException {
        Map<String,Object> stringObjectMap =  new HashMap<>();
        CountDownLatch countDownLatch = new CountDownLatch(10);

        ThreadPoolUtils.getThreadPoolExecutor().submit(new Runnable() {
            @Override
            public void run() {
                Integer totalMember = showMapper.findMember();
                stringObjectMap.put("totalMember",totalMember);
                countDownLatch.countDown();
            }
        });
        ThreadPoolUtils.getThreadPoolExecutor().submit(new Runnable() {
            @Override
            public void run() {
                Integer todayNewMember = showMapper.insertMember();
                stringObjectMap.put("todayNewMember",todayNewMember);
                countDownLatch.countDown();
            }
        });
        ThreadPoolUtils.getThreadPoolExecutor().submit(new Runnable() {
            @Override
            public void run() {
                Integer thisWeekNewMember = showMapper.insertMemberWeek();
                stringObjectMap.put("thisWeekNewMember",thisWeekNewMember);
                countDownLatch.countDown();
            }
        });
        ThreadPoolUtils.getThreadPoolExecutor().submit(new Runnable() {
            @Override
            public void run() {
                Integer thisMonthNewMember = showMapper.insertMemberMouth();
                stringObjectMap.put("thisMonthNewMember",thisMonthNewMember);
                countDownLatch.countDown();
            }
        });
        ThreadPoolUtils.getThreadPoolExecutor().submit(new Runnable() {
            @Override
            public void run() {
                List<Map> hotSetmeal = showMapper.hotSetmeal();
                stringObjectMap.put("hotSetmeal",hotSetmeal);
                countDownLatch.countDown();
            }
        });
        ThreadPoolUtils.getThreadPoolExecutor().submit(new Runnable() {
            @Override
            public void run() {
                Integer todayOrderNumber = showMapper.insertOrder();
                stringObjectMap.put("todayOrderNumber",todayOrderNumber);
                countDownLatch.countDown();
            }
        });
        ThreadPoolUtils.getThreadPoolExecutor().submit(new Runnable() {
            @Override
            public void run() {
                Integer thisMonthOrderNumber = showMapper.insertOrderMouth();
                stringObjectMap.put("thisMonthOrderNumber",thisMonthOrderNumber);
                countDownLatch.countDown();
            }
        });
        ThreadPoolUtils.getThreadPoolExecutor().submit(new Runnable() {
            @Override
            public void run() {
                Integer thisWeekOrderNumber = showMapper.insertOrderWeek();
                stringObjectMap.put("thisWeekOrderNumber",thisWeekOrderNumber);
                countDownLatch.countDown();
            }
        });
        ThreadPoolUtils.getThreadPoolExecutor().submit(new Runnable() {
            @Override
            public void run() {
                Integer todayVisitsNumber = showMapper.insterorderstatus();
                stringObjectMap.put("todayVisitsNumber",todayVisitsNumber);
                countDownLatch.countDown();
            }
        });
        ThreadPoolUtils.getThreadPoolExecutor().submit(new Runnable() {
            @Override
            public void run() {
                Integer thisWeekVisitsNumber = showMapper.insterorderstatusweeks();
                stringObjectMap.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
                countDownLatch.countDown();
            }
        });
        ThreadPoolUtils.getThreadPoolExecutor().submit(new Runnable() {
            @Override
            public void run() {
                Integer thisMonthVisitsNumber = showMapper.insterorderstatusmouths();
                stringObjectMap.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
                countDownLatch.countDown();
            }
        });

        countDownLatch.await();

        return stringObjectMap;
    }
}
